var ClubMessageWindow = Window.extend({
    _ccsFileName: res.ClubMessageWindow_json,
    _messageList: [],
    initWindow: function (mesageList) {
        this._messageList = mesageList;
        this._nodeList['no_info_tip'].setVisible(this._messageList.length == 0);
        this._initTableView();
    },
    /**
     * 监听亲友圈消息
     * @private
     */
    _initEventListeners: function () {
        this._eventListeners = {};
        //监听 消息 事件
        this._eventListeners[ClubMsgCode.AgreeClub] = '_clubAgreeClubHandler';
        this._eventListeners[ClubMsgCode.QueryMSG] = '_queryMSGHandelr';
    },

    /**
     * 初始化TableView
     * @private
     */
    _initTableView: function () {
        var nodeContent = this._nodeList['nodeContent'];
        var tableViewSize = nodeContent.getContentSize();
        this._tableView = new cc.TableView(this, cc.size(tableViewSize.width, tableViewSize.height));
        this._tableView.setDelegate(this);
        this._tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
        this._tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
        nodeContent.addChild(this._tableView);
    },

    _clubAgreeClubHandler: function () {
        clubMsgManager.requestClubMsg();
    },
    /**
     * 亲友圈消息
     * @private
     */
    _queryMSGHandelr: function (data) {
        if (data.result != 0) {
            showAlert(data['msg']);
            return;
        }
        this._messageList = [];
        for (var i = 0; i < data['arr'].length; i++) {
            if (data['arr'][i].type == 'invite') {
                this._messageList.push(data['arr'][i]);
            }
        }
        this._nodeList['no_info_tip'].setVisible(this._messageList.length == 0);
        this._tableView.reloadData();
    },


    tableCellAtIndex: function (table, idx) {
        var cell = table.dequeueCell();
        var node = null;
        if (cell == null) {
            cell = new cc.TableViewCell();
            node = addItem('ClubMessageItem', cell, (idx + 1), this._messageList[idx]);
            node.setName("itemCell");
        } else {
            node = cell.getChildByName("itemCell");
            node.setData((idx + 1), this._messageList[idx]);
        }
        return cell;
    },
    tableCellTouched: function (table, cell) {
    },
    tableCellSizeForIndex: function (table, idx) {
        return cc.size(1163, 86);
    },
    numberOfCellsInTableView: function (table) {
        return this._messageList.length;
    },

    close: function () {
        Window.prototype.close.call(this);
        ClubViewUtil.openClubMainWindow();
    },

});